//
//  DataPickerViewController.m
//  OCUI
//
//  Created by login on 15-7-27.
//
//

#import "DataPickerViewController.h"
#define DEFAULTCOLOR [UIColor colorWithRed:61.0/255.0 green:154.0/255.0 blue:240.0/255.0 alpha:1.0]

@interface DataPickerViewController ()
{
    BOOL isShow;
    UIView *dateView;
}
@end

@implementation DataPickerViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    self.view.backgroundColor = [UIColor whiteColor];
    
    
    UIButton *button = [[UIButton alloc]initWithFrame:CGRectMake(50, 100, 100, 40)];
    [button setBackgroundColor:[UIColor redColor]];
    [button addTarget:self action:@selector(dddd) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:button];
    
    isShow = NO;
    
    dateView = [[UIView alloc]initWithFrame:CGRectMake(0, self.view.frame.size.height, self.view.frame.size.width, [UIScreen mainScreen].bounds.size.height/3 + 30)];
    [self.view addSubview:dateView];
    
    UIButton *cancelButton = [[UIButton alloc]initWithFrame:CGRectMake(0, 0, 50, 30)];
    [cancelButton setTitle:@"取消" forState:UIControlStateNormal];
    [cancelButton setTitleColor:DEFAULTCOLOR forState:UIControlStateNormal];
    [dateView addSubview:cancelButton];
    
    UIButton *confirmButton = [[UIButton alloc]initWithFrame:CGRectMake(self.view.frame.size.width - 50, 0, 50, 30)];
    [confirmButton setTitle:@"确定" forState:UIControlStateNormal];
    [confirmButton setTitleColor:DEFAULTCOLOR forState:UIControlStateNormal];
    [dateView addSubview:confirmButton];
    
    UIDatePicker *datePicker = [[UIDatePicker alloc]initWithFrame:CGRectMake(0, 30, self.view.frame.size.width, [UIScreen mainScreen].bounds.size.height/3)];
    datePicker.datePickerMode = UIDatePickerModeDateAndTime;
    [datePicker addTarget:self action:@selector(dateChanged:) forControlEvents:UIControlEventValueChanged ];
    [dateView addSubview:datePicker];

}

- (void)dddd
{

    if (isShow == NO) {
        [UIView animateWithDuration:0.5 animations:^{
            dateView.frame = CGRectMake(0, self.view.frame.size.height - 246, self.view.frame.size.width, [UIScreen mainScreen].bounds.size.height/3+30);
        }];

        isShow = YES;
    }else{
        [UIView animateWithDuration:0.5 animations:^{
            dateView.frame = CGRectMake(0, self.view.frame.size.height, self.view.frame.size.width, [UIScreen mainScreen].bounds.size.height/3+30);
        }];
        isShow = NO;
    }
    
}

-(void)dateChanged:(id)sender{
    UIDatePicker *control = (UIDatePicker*)sender;
    NSDate* _date = control.date;
    NSDateFormatter *formatter = [[NSDateFormatter alloc]init];
    formatter.dateFormat = @"yyyy-MM-dd HH:mm:ss";
    NSString *dateString = [formatter stringFromDate:_date];
    NSLog(@"%@",dateString);
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
